home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14420 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  93 lines

  1. Path: argonet.co.uk!argbd86
  2. From: Charlotte Tomlinson <eeyore@argonet.co.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Urgent help - pointers to functions
  5. Date: Sat, 30 Mar 1996 11:57:33
  6. Organization: UnipalmPIPEX server (post doesn't reflect views of UnipalmPIPEX
  7. Distribution: world
  8. Message-ID: <internews46B6FAA4E6@argonet.co.uk>
  9. Reply-To: Charlotte Tomlinson <eeyore@argonet.co.uk>
  10. NNTP-Posting-Host: ao093.du.pipex.com
  11. X-Newsreader: VTi Voyager InterNews 0.15 for Acorn RISC OS (Patched by RA)
  12.  
  13. I have implemented a template doubly linked list, the backbones of which
  14. is as follows:
  15.  
  16. //dllist.h
  17.  
  18. /*snip*/
  19.  
  20. template <class T> class node
  21. {
  22.         public:
  23.         T data;
  24.         node<T> *next;
  25.         node<T> *prev;
  26.         node();
  27.         node(T info);
  28.         node<T> *getnext() const {return next;}
  29.         node<T> *getprev() const {return prev;}
  30.         T getinfo() const {return data;}
  31.         void change(T info) {data=info;}
  32. /*other functions*/
  33. };
  34.  
  35. template <class T> class dllist : public node<T>
  36. {
  37.         node<T> *start, *end;
  38.         void copy(const dllist<T>);
  39.  
  40.         public:
  41.         dllist() {start=end=NULL;}
  42.         dllist(const dllist<T>&);
  43.         int isEmpty() const;
  44. /*store, remove, find, ==, etc. snipped*/
  45. };
  46.  
  47.  
  48. Then I have a class, called fuzzyset, which uses this dll as a container
  49. for fuzzyel instances:
  50.  
  51. //fuzzyset.h
  52. /*snip*/
  53.  
  54. class fuzzyset {
  55.         private:
  56.         dllist<fuzzyel> members;
  57.  
  58.         public:
  59.         fuzzyset() {}
  60.         fuzzyset(const fuzzyset&);
  61.         fuzzyset(const fuzzyel&);
  62. /*other functions and operators*/
  63. };
  64.  
  65.  
  66. What I would like to do is, within dllist, to implement a function forEach
  67. that take a pointer to a function as one argument, and somehow the rest of
  68. the arguments required by that function, and carries that function out
  69. over each element of the list. 
  70.  
  71. One example of what I need to do is as follows.  In my main program (where
  72. fuzzyset is included), I need to be able to call a function that prints
  73. every element of the 'members' list in any called instance of a fuzzyset.
  74.  
  75. I need the forEach function to be quite generic, because I will have other
  76. uses for it later.
  77.  
  78. I hope someone can help.  Many thanks in advance.
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. ... *Configure Boot Big
  86. -- 
  87. -----------------------------------------------------------------------------
  88. | Charlotte Tomlinson  |    Mediocrity know nothing higher than itself,     |
  89. | eeyore@argonet.co.uk |       but talent instantly recognises genius.      |
  90. |---------------------------------------------------------------------------|
  91. --------- Now WWWebbed up at http://www.argonet.co.uk/users/eeyore/ ---------
  92.  
  93.